import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { routerRedux } from 'dva/router';
import { query as _query } from "../services/error";
export default {
  namespace: 'error',
  state: {
    error: '',
    isloading: false,
    globalException: {
      history: JSON.parse(localStorage.getItem('cpaas-global-exception-history') || '[]')
    },
    // 运行时捕获的异常
    normal501: {} // 正常的501错误

  },
  effects: {
    query: /*#__PURE__*/_regeneratorRuntime.mark(function query(_ref, _ref2) {
      var payload, call, put;
      return _regeneratorRuntime.wrap(function query$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(_query, payload.code);

            case 4:
              _context.next = 6;
              return put(routerRedux.push("/exception/".concat(payload.code)));

            case 6:
              _context.next = 8;
              return put({
                type: 'trigger',
                payload: payload.code
              });

            case 8:
            case "end":
              return _context.stop();
          }
        }
      }, query);
    })
  },
  reducers: {
    trigger: function trigger(state, action) {
      return {
        error: action.payload
      };
    },
    updateState: function updateState(state, _ref3) {
      var payload = _ref3.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};